import { useEffect, useState, useRef } from 'react';
import {
  ProFormText,
  ProFormSelect,
  ProFormDependency,
  ProForm,
  ProFormRadio,
  ProFormTextArea,
  ProFormItem,
  ProFormDateTimeRangePicker,
} from '@ant-design/pro-components';
import { Button, DatePicker } from 'antd';
import { isEmpty, sortBy, uniqBy } from 'lodash';
import useDetailType from '@/hooks/useDetailType';
import type Umi from 'umi';
import type { ProFormInstance } from '@ant-design/pro-components';
import {
  queryOptionsPlaceChannelList,
  queryOptionsActivityGrouplist,
  queryOptionsUseChannelList,
  queryOptionsUsetabList,
  queryOptionsNotifyRuleList,
  queryOptionsActivityProductkeyList,
  queryOptionsStoreTypeList,
  queryOptionsDaypartList,
  queryUseChannelTemp,
  queryProfileTemp,
  queryOptionsStoreGrouplist,
  queryOptionsDategroupList,
  queryOptionsTenantList,
} from '@/services/profile';
import StorageManager from '@/utils/StorageManager';

import useDispatcher from '../hooks/useDispatcher';
import getProFileData from '../getProFileData';
import {
  ENUM_PROFILE_STATUS,
  ENUM_BUSINESS_MODEL,
  ENUM_COUPON_TYPE_NAME,
  ENUM_ISSUER_NAME,
  ENUM_COUPON_SOURCE,
  ENUM_PLAC_STYLE,
  ENUM_DISCOUNT_LEVEL,
  ENUM_PLACE_TYPE_LEVEL,
  ENUM_SORT_GROUP,
  ENUM_REGION_LIMIT_TYPE,
  ENUM_BRAND,
} from '../constants';
import Config from '../configGroup';
import TenantRadio from './tenantRadio';
import styles from './style.less';
import moment from 'moment';

type PropsFromModel = Umi.TProfileModelState;

type Props = {
  isModify?: boolean;
  isRead?: boolean;
  formRef: ProFormInstance | any;
  profile: PropsFromModel;
};

interface IParams {
  type?: string;
  id?: string;
}

const BasicInfo: React.FC<Props> = ({ formRef }) => {
  //   const formInstance = ProForm.useFormInstance();
  const { isAdd, isModify, params } = useDetailType<IParams>();
  const isFirst = useRef(true);
  const dispatch = useDispatcher();
  const { formValue } = getProFileData();

  const eunmList: any = StorageManager.getLocalStorageSync('eunmList');
  const OptionsBrandList = eunmList?.OptionsBrandList || [];
  const OptionsActivityGroupTypeListBro = eunmList?.OptionsActivityGroupTypeListBro || [];
  const LASTESTTOP = eunmList?.LASTESTTOP || [];
  const OptionsCouponTagList = eunmList?.OptionsCouponTagList || [];
  const OptionsBusinessTypeList = eunmList?.OptionsBusinessTypeList || [];
  const OptionsCouponUseCategoryList = eunmList?.OptionsCouponUseCategoryList || [];
  const OptionsRegionList = eunmList?.OptionsRegionList || [];
  const OptionsFilterTagList = eunmList?.OptionsFilterTagList || [];
  const OptionsExtandvalueInfoList = eunmList?.OptionsExtandvalueInfoList || [];

  const [optionsPlaceChannelList, setOptionsPlaceChannelList] = useState([] as API.OptionsKeys[]); // 平台--枚举
  const [OptionsActivityGrouplist, setOptionsActivityGrouplist] = useState([] as API.OptionsKeys[]); // 活动组--组二--枚举
  const [OptionsUseChannelList, setOptionsUseChannelList] = useState([] as API.OptionsKeys[]); // 券使用渠道描述--枚举
  const [OptionsTenantList, setOptionsTenantList] = useState([] as API.OptionsKeys[]); // 券使用渠道描述--枚举

  const [OptionsCouponTagsValueList, setOptionsCouponTagsValueList] = useState(
    [] as API.OptionsKeys[],
  ); // 券标签--的第二个下拉框的枚举
  const [profileTemp, setProfileTemp] = useState({} as API.ProfileTempDetail); // 活动组--的第一个下拉框的枚举

  // 接口(2.2.4)查询根据结果初始化值
  const getProfileTemp = async (brandName: string, placeChannelName: string) => {
    const { code, data } = await queryProfileTemp({ brandName, placeChannelName });
    if (code === 200 && data) {
      dispatch('setSoloValue', {
        lable: 'QueryChannelIdUniq',
        value: data.queryChannelId ? data.queryChannelId.split(',') : [],
      });
      setProfileTemp(data);
      const object: Partial<API.ProfileTempDetail> = {
        couponSource: data.couponSource,
        businessModel: data.businessModel,
        couponTypeName: data.couponTypeName,
        placeStyle: data.placeStyle,
        useChannelName: data.useChannelName,
        category: data.category,
        subCategory: data.subCategory,
        occasion: data.occasion,
        placeScope: data.placeScope,
        placeChannel: data.placeChannel,
        invoiceType: data.invoiceType,
        payerName: data.payerName,
        applyName: data.applyName,
        faceAmount: data.faceAmount,
        sales: data.sales,
        discountinSales: data.discountinSales,
        invoiceAmountA: data.invoiceAmountA,
        invoiceAmountB: data.invoiceAmountB,
        issuerName: data.issuerName,
        placeType: data.placeType,
        count: data.count,
        countCheck: data.count === -1 ? ['不限制'] : [],
        personLimitCount: data.personLimitCount,
        personLimitCountCheck: data.personLimitCount === -1 ? ['不限制'] : [],
        reusableCount: data.reusableCount,
        reusableCountCheck: data.reusableCountCheck === -1 ? ['不限制'] : [],
        salesType: data.salesType,
        tenderTypeDesc: data.tenderTypeDesc,
        useRuleTypeName: data.useRuleTypeName,
        priceRule: data.priceRule,
        discountPrice: data.discountPrice,
        returnDiscount: data.returnDiscount,
        placeChannelId: data.placeChannelId,
        queryChannelId: data.queryChannelId.split(','),
        needGenAsynFile: data.needGenAsynFile,
        lastestTop: data.lastestTop,
      };
      formRef.current?.setFieldsValue(object);
      dispatch('setFormValue', object);
    } else {
      const object: any = {
        couponSource: 'YUM券平台',
        businessModel: 'B2C',
        couponTypeName: '产品',
        placeStyle: '积分兑换',
        useChannelName: '',
        category: '',
        subCategory: '',
        occasion: '',
        placeScope: '',
        placeChannel: '',
        invoiceType: 'N/A',
        payerName: '',
        applyName: '',
        faceAmount: -1,
        sales: '',
        discountinSales: -1,
        invoiceAmountA: -1,
        invoiceAmountB: -1,
        issuerName: 'YUM',
        placeType: '不导出券码',
        count: '',
        countCheck: [],
        personLimitCount: '',
        personLimitCountCheck: [],
        reusableCount: '',
        reusableCountCheck: [],
        salesType: 0,
        tenderTypeDesc: '折扣',
        useRuleTypeName: '',
        priceRule: -1,
        discountPrice: -1,
        returnDiscount: -100,
        placeChannelId: '',
        queryChannelId: [],
        needGenAsynFile: '',
        lastestTop: 0,
        givingLimit: 0,
      };
      formRef.current?.setFieldsValue(object);
      dispatch('setFormValue', object);
    }
  };

  const getUseChannelTemp = async (brandName: string, useChannelName: string) => {
    const { code, data } = await queryUseChannelTemp({ brandName, useChannelName });
    if (code === 200 && data) {
      // setProfileTemp(data);
      formRef.current?.setFieldsValue({ useChannelId: data.split(',') });
      dispatch('setFormValue', { useChannelId: data.split(',') });
    }
  };

  // 监听发放平台--变化--联动
  useEffect(() => {
    if (isFirst.current && params.id) {
      // todo: 查询模版这里通过ref校验+id
      // 编辑第一次进来不可以复默认值
      isFirst.current = false;
      return;
    }

    if (formValue.placeChannelName) {
      // 发放平台变了
      getProfileTemp(formValue.brandName, formValue.placeChannelName);
    }
    if (formValue.useChannelName) {
      // 券使用渠道描述变了
      getUseChannelTemp(formValue.brandName, formValue.useChannelName);
    }
  }, [formValue.placeChannelName, formValue.useChannelName]);

  // // 监听--变化--联动
  // useEffect(() => {
  //   if (formValue.useChannelName) {
  //     // todo: 查询模版这里通过ref校验+id
  //     if (isFirst.current && params.id) {
  //       // 编辑第一次进来不可以复默认值
  //       isFirst.current = false;
  //       return;
  //     }
  //     // 券使用渠道描述变了
  //     getUseChannelTemp(formValue.brandName, formValue.useChannelName);
  //   }
  // }, [formValue.useChannelName]);

  //  劵标签--新增
  const handlecouponTags = (couponTagsLabel: string, couponTagsValue: string) => {
    if (isEmpty(couponTagsLabel) || isEmpty(couponTagsValue)) return;
    // Json 互转
    const couponTags = formRef.current?.getFieldValue('couponTags') || {};
    const couponTagsBro = couponTags.length > 2 ? JSON.parse(couponTags) : {};
    couponTagsBro[couponTagsLabel] = couponTagsValue;
    formRef.current?.setFieldValue('couponTags', JSON.stringify(couponTagsBro));
    dispatch('setFormValue', { couponTags: JSON.stringify(couponTagsBro) });
  };

  //  扩展属性--新增
  const handleExtandValue = (extandValueOne: string, extandValueTwo: string) => {
    if (isEmpty(extandValueOne) || isEmpty(extandValueTwo)) return;
    // Json 互转
    const extandValue = formRef.current?.getFieldValue('extandValue') || {};
    const extandValueBro = extandValue.length > 2 ? JSON.parse(extandValue) : {};
    extandValueBro[extandValueOne] = extandValueTwo;
    formRef.current?.setFieldValue('extandValue', JSON.stringify(extandValueBro));
    dispatch('setFormValue', { extandValue: JSON.stringify(extandValueBro) });
  };

  const getOptionsActivityGrouplist = async (e: string, value: any, isReset: boolean) => {
    const { data, code } = await queryOptionsActivityGrouplist({ brandId: e, groupTypeId: value });
    if (code === 200) {
      const arr = [] as API.OptionsKeys[];
      data?.forEach((item: API.OptionsActivityGroupItem) => {
        arr.push({
          label: item.activityGroup,
          value: item.activityGroup,
          // value: String(item.id),
        });
      });
      setOptionsActivityGrouplist(arr);
      if (arr.length > 0) {
        // PH--Prime前端自己添加有值的情况
        arr.push({
          label: 'Prime',
          value: 'Prime',
        });
        if (isReset) {
          formRef.current?.setFieldValue('activityGroup', arr[0].value || '');
          dispatch('setFormValue', { activityGroup: arr[0].value || '' });
        }
      } else {
        formRef.current?.setFieldValue('activityGroup', '');
        dispatch('setFormValue', { activityGroup: '' });
      }
    }
  };

  const getOptionsPlaceChannelList = async (e: string, isReset: boolean) => {
    const { data, code } = await queryOptionsPlaceChannelList({ brandName: e });
    if (code === 200 && data) {
      const arr = [] as API.OptionsKeys[];
      data?.forEach((item: API.OptionsPlaceChannelListItem) => {
        arr.push({
          label: item.placeChannelName,
          value: item.placeChannelName,
          id: item.id,
        });
      });
      setOptionsPlaceChannelList(arr);
      // setOptionsPlaceChannelList(sortBy(arr, 'id'));
      // console.log('formValue----不是吧', formValue.placeChannelName, formValue);
      // 编辑旧的平台数据时，placeChannelName为null---todo
      // if (formValue.placeChannelId && data.length > 0) {
      //   const litsBro: any = data?.filter(
      //     (items: any) => items.placeChannelId == formValue.placeChannelId,
      //   );
      //   formRef.current?.setFieldValue(
      //     'placeChannelName',
      //     litsBro.length > 0 ? litsBro[0].value : '',
      //   );
      //   dispatch('setFormValue', { placeChannelName: litsBro.length > 0 ? litsBro[0].value : '' });
      // }
      if (isReset) {
        formRef.current?.setFieldValue('placeChannelName', arr.length > 0 ? arr[0].value : '');
        dispatch('setFormValue', { placeChannelName: arr.length > 0 ? arr[0].value : '' });
      }
    }
  };

  const getOptionsUsetabList = async (e: string) => {
    const { data, code } = await queryOptionsUsetabList({ brandId: e });
    if (code === 200) {
      const arr = [] as API.OptionsKeys[];
      data?.forEach((item: API.OptionsUsetabListItem) => {
        arr.push({
          label: item.useTabName,
          value: String(item.useTab),
          // value: String(item.id),
        });
      });
      dispatch('setSoloValue', {
        lable: 'OptionsUsetabList',
        value: arr,
      });
    }
  };

  const getOptionsNotifyRuleList = async (e: string) => {
    const { data, code } = await queryOptionsNotifyRuleList({ brandName: e });
    if (code === 200) {
      const arr = [] as API.OptionsKeys[];
      data?.forEach((item: API.OptionsNotifyRuleListItem) => {
        arr.push({
          label: item.notifyRuleName,
          value: item.notifyRuleName,
          // value: String(item.id),
        });
      });
      dispatch('setSoloValue', {
        lable: 'OptionsNotifyRuleList',
        value: arr,
      });
    }
  };

  const getOptionsActivityProductkeyList = async (e: string) => {
    const { data, code } = await queryOptionsActivityProductkeyList({ brandId: e });
    if (code === 200) {
      const arr = [] as API.OptionsKeys[];
      data?.forEach((item: API.OptionsActivityProductkeyListItem) => {
        arr.push({
          label: item.id + '-' + item.productKeyName,
          value: item.id,
          item: { ...item },
        });
      });
      dispatch('setSoloValue', {
        lable: 'OptionsActivityProductkeyList',
        value: arr,
      });
    }
  };

  const getOptionsStoreTypeList = async (e: string) => {
    const { data, code } = await queryOptionsStoreTypeList({ brandId: e });
    if (code === 200) {
      const arr = [] as API.OptionsKeys[];
      data?.forEach((item: API.OptionsStoreTypeListItem) => {
        arr.push({
          label: item.storeTypeCode + '-' + item.storeTypeName,
          value: String(item.storeTypeCode),
        });
      });
      dispatch('setSoloValue', {
        lable: 'OptionsStoreTypeList',
        value: arr,
      });
    }
  };

  const getOptionsDaypartList = async (e: string) => {
    const { data, code } = await queryOptionsDaypartList({ brandId: e });
    if (code === 200) {
      const arr = [] as API.OptionsKeys[];
      data?.forEach((item: API.OptionsDaypartListItem) => {
        arr.push({
          label: item.dayPartCode + '-' + item.dayParteName,
          value: String(item.dayPartCode),
        });
      });
      dispatch('setSoloValue', {
        lable: 'OptionsDaypartList',
        value: arr,
      });
    }
  };

  const getOptionsStoreGrouplist = async (e: string) => {
    const { data, code } = await queryOptionsStoreGrouplist({ brandId: e });
    if (code === 200) {
      const arr = [] as API.OptionsKeys[];
      data?.forEach((item: API.OptionsStoreGrouplistItem) => {
        arr.push({
          label: item.storegroup + '-' + item.storegroupname,
          value: item.storegroup,
        });
      });
      dispatch('setSoloValue', {
        lable: 'OptionsStoreGrouplist',
        value: arr,
      });
    }
  };

  const getOptionsDategroupList = async (e: string) => {
    const { data, code } = await queryOptionsDategroupList({ brandId: e });
    if (code === 200) {
      const arr = [] as API.OptionsKeys[];
      data?.forEach((item: API.OptionsDategroupListItem) => {
        arr.push({
          label: item.dateGroup + '-' + item.dateGroupName,
          value: item.dateGroup,
        });
      });
      dispatch('setSoloValue', {
        lable: 'OptionsDategroupList',
        value: arr,
      });
    }
  };

  const getOptionsUseChannelList = async (e: string, isReset: boolean) => {
    const { data, code } = await queryOptionsUseChannelList({ brandName: e });
    if (code === 200) {
      const arr = [] as API.OptionsKeys[];
      data?.forEach((item: API.OptionsUseChannelListItem) => {
        arr.push({
          label: item.couponUseType + '-' + item.useChannelName,
          value: item.useChannelName,
          couponUseType: item.couponUseType,
          // value: item.id,
        });
      });
      setOptionsUseChannelList(sortBy(arr, 'couponUseType'));
      if (isReset) {
        formRef.current?.setFieldValue('useChannelName', arr.length > 0 ? arr[0].value : '');
        dispatch('setFormValue', { useChannelName: arr.length > 0 ? arr[0].value : '' });
      }
    }
  };

  // 租户列表查询
  const getOptionsTenantList = async (e: string, isReset: boolean) => {
    const { data, code } = await queryOptionsTenantList({ brandId: e });
    if (code === 200 && data) {
      const FatherListUniq: string[] = [];
      data?.forEach((item: API.OptionsTenantListItem) => {
        FatherListUniq.push(item.id);
        item.label = item.name;
        item.title = item.name;
        item.value = item.id;
        item.key = item.id;

        if (item.children) {
          item.children.forEach((items) => {
            items.label = items.name;
            item.title = item.name;
            items.value = items.id;
            items.key = items.id;
          });
        } else {
          item.children = [];
        }
      });
      // 平铺二维数组数据
      let OptionsTenantListUniq = [...data];
      OptionsTenantListUniq.forEach((item) => {
        if (item.children.length > 0) {
          OptionsTenantListUniq = [...OptionsTenantListUniq, ...item.children];
        }
      });

      dispatch('setSoloValue', {
        lable: 'OptionsTenantListUniq',
        value: OptionsTenantListUniq,
      });

      dispatch('setSoloValue', {
        lable: 'FatherListUniq',
        value: FatherListUniq,
      });

      setOptionsTenantList([...data]);
      // isReset 是否重新赋值
      if (isReset) {
        const obj = {
          tenantFather: data.length > 0 ? data[0].id : '',
          tenantList: [],
        };
        formRef.current?.setFieldsValue({ ...obj });
        dispatch('setFormValue', { ...obj });
      }
    }
  };

  // 枚举值查询---编辑时
  useEffect(() => {
    // dispatch('queryOptionsActivityGroupTypeList');
    // dispatch('queryOptionsKeys');
    // dispatch('queryOptionsBrandList');
    // dispatch('queryOptionsChannelList');
    // getOptionsActivityGroupTypeList();
    // dispatch('queryOptionsCouponTagList');
    // dispatch('queryOptionsBusinessTypeList');
    // dispatch('queryOptionsCouponUseCategoryList');
    // dispatch('queryOptionsRegionList');
    // dispatch('queryOptionsFilterTagList');
    // dispatch('queryOptionsExtandvalueInfoList');

    if (params.id && (isModify || isAdd)) {
      // 编辑进来需要查询枚举--同 optionsBrandChange
      const brandItem = ENUM_BRAND.filter((item) => item.label === formValue.brandName);
      // 给品牌id-赋值
      dispatch('setFormValue', { brandId: brandItem[0].value || '' });
      formRef.current?.setFieldValue('brandId', brandItem[0].value || '');
      // 给活动组--组一--赋值
      formRef.current?.setFieldValue('groupTypeId', formValue?.groupTypeId || 1);
      dispatch('setFormValue', {
        groupTypeId: formValue?.value || 1,
      });

      const e = brandItem[0].value || '';
      if (e) {
        // 发放平台--赋值
        getOptionsPlaceChannelList(brandItem[0].label || '', false);
        // 活动组--组二--赋值
        getOptionsActivityGrouplist(e, formValue?.groupTypeId || 1, false);
        // 券使用渠道描述--赋值
        // getOptionsUseChannelList(brandItem.length > 0 ? brandItem[0].label : '', false);
        // 租户列表--赋值
        getOptionsTenantList(brandItem.length > 0 ? brandItem[0].value : '', false);
        // 卡包栏位
        getOptionsUsetabList(e);
        // 规则名称
        getOptionsNotifyRuleList(brandItem[0].label || '');
        // 键位模板
        getOptionsActivityProductkeyList(e);
        // 餐厅类型
        getOptionsStoreTypeList(e);
        // 用餐时间ID
        getOptionsDaypartList(e);
        // 餐厅组
        getOptionsStoreGrouplist(e);
        // 日期组
        getOptionsDategroupList(e);
      }
    }
  }, []);

  // 切换品牌  重新拉枚举接口，并进行默认赋值
  const optionsBrandChange = (e: string) => {
    const brandItem = OptionsBrandList.filter((item: any) => item.value === e);
    // 给品牌名称赋值
    dispatch('setFormValue', { brandName: brandItem[0].label || '' });
    // 给活动组--组一--赋值  formValue
    formRef.current?.setFieldValue('groupTypeId', OptionsActivityGroupTypeListBro[0]?.value || 1);
    dispatch('setFormValue', {
      groupTypeId: OptionsActivityGroupTypeListBro[0]?.value || 1,
    });

    if (e) {
      // 如果选择的PHDI，排序分组选中1
      if (String(e) === '003') {
        formRef.current?.setFieldValue('sortGroup', String(e) === '2' ? 1 : 0);
        dispatch('setFormValue', {
          sortGroup: String(e) === '003' ? 1 : 0,
        });
      }
      // 发放平台--赋值
      getOptionsPlaceChannelList(brandItem[0].label || '', true);
      // 活动组--组二--赋值
      getOptionsActivityGrouplist(e, OptionsActivityGroupTypeListBro[0]?.value || 1, true);
      // 券使用渠道描述--赋值
      // getOptionsUseChannelList(brandItem.length > 0 ? brandItem[0].label : '', true);
      // 租户列表--赋值
      getOptionsTenantList(brandItem.length > 0 ? brandItem[0].value : '', true);
      // 卡包栏位
      getOptionsUsetabList(e);
      // 规则名称
      getOptionsNotifyRuleList(brandItem[0].label || '');
      // 键位模板
      getOptionsActivityProductkeyList(e);
      // 餐厅类型
      getOptionsStoreTypeList(e);
      // 用餐时间ID
      getOptionsDaypartList(e);
      // 餐厅组
      getOptionsStoreGrouplist(e);
      // 日期组
      getOptionsDategroupList(e);
    }
  };

  // 切换活动组--组一  重新拉--组二--枚举接口，并进行--组二--默认赋值
  const optionsActivityGroupChange = (e: string) => {
    if (e) {
      const brandId = formRef.current?.getFieldValue('brandId') || '';
      getOptionsActivityGrouplist(brandId, e, true);
    } else {
      formRef.current?.setFieldValue('activityGroup', '');
    }
  };

  // 切换券标签--lable  给标签值---默认赋值
  const optionsCouponTagListChange = (e: string) => {
    const itemBro = OptionsCouponTagList.filter((item: any) => item.value === e);
    if (itemBro.length > 0) {
      formRef.current?.setFieldValue('couponTagsValue', itemBro[0].tagvalue || '');
      dispatch('setFormValue', { couponTagsValue: itemBro[0].tagvalue || '' });
      const list: any = [];
      itemBro.forEach((items: any) => {
        list.push({
          label: items.tagvalue,
          value: items.tagvalue,
        });
      });
      setOptionsCouponTagsValueList(list);
    }
  };

  // 切换扩展属性---默认赋值
  const extandValueOneChange = () => {
    formRef.current?.setFieldValue('extandValueTwo', '');
    dispatch('setFormValue', { extandValueTwo: '' });
  };

  const onChangeStartTime = (date: any, dateString: string) => {
    formRef.current?.setFieldValue('activityStartTime', dateString);
    dispatch('setFormValue', { activityStartTime: dateString });
  };

  const onChangeEndTime = (date: any, dateString: string) => {
    formRef.current?.setFieldValue('activityEndTime', dateString);
    dispatch('setFormValue', { activityEndTime: dateString });
  };

  return (
    <Config.Group id="basic-info" title="基本信息">
      <div className={styles['wrap-body']}>
        <ProForm.Group>
          <ProFormText
            labelCol={{ span: 8 }}
            width="lg"
            name="activityId"
            label="活动定义"
            placeholder="activityId"
            rules={[
              { required: true, message: '不得为空' },
              {
                validator: (_, value) => {
                  if (value && value.indexOf('-') !== -1)
                    return Promise.reject(new Error('活动定义不能包含符号-'));
                  return Promise.resolve();
                },
              },
            ]}
            disabled={isModify}
          />

          <ProFormSelect
            labelCol={{ span: 8 }}
            width="lg"
            name="profileStatus"
            label="主档状态"
            disabled={true}
            options={ENUM_PROFILE_STATUS}
            placeholder="填写中"
          />
        </ProForm.Group>
        <ProForm.Group>
          <ProFormSelect
            labelCol={{ span: 8 }}
            width="lg"
            name="brandId"
            label="品牌"
            options={OptionsBrandList}
            placeholder="请选择品牌"
            fieldProps={{
              listHeight: 350,
              onChange: (e) => optionsBrandChange(e),
            }}
            rules={[{ required: true, message: '不得为空' }]}
          />

          <ProFormSelect
            labelCol={{ span: 8 }}
            width="lg"
            name="placeChannelName"
            label="发放平台"
            options={optionsPlaceChannelList}
            placeholder="请选择发放平台"
            // rules={[{ required: true, message: '不得为空' }]}
          />
        </ProForm.Group>

        <ProForm.Group>
          <ProFormSelect
            labelCol={{ span: 8 }}
            style={{ width: '48%' }}
            name="groupTypeId"
            label="活动组"
            options={OptionsActivityGroupTypeListBro}
            placeholder=""
            fieldProps={{
              onChange: optionsActivityGroupChange,
            }}
          />

          <div style={{ width: 128 }}>
            <ProFormSelect
              labelCol={{ span: 0 }}
              style={{ width: 128, marginLeft: '-48%' }}
              name="activityGroup"
              label={null}
              options={OptionsActivityGrouplist}
              placeholder=""
              fieldProps={{
                listHeight: 350,
              }}
            />
          </div>
        </ProForm.Group>

        <ProForm.Group>
          <ProFormText
            labelCol={{ span: 8 }}
            width="lg"
            name="activityGroupRound"
            label="活动组批次"
            placeholder="activityGroupRound"
          />

          <ProFormText
            labelCol={{ span: 8 }}
            width="lg"
            name="needGenasynfile"
            label="发放标签"
            placeholder="needGenasynfile"
            disabled={true}
          />

          <ProFormText
            labelCol={{ span: 8 }}
            width="lg"
            name="activity"
            label="劵名"
            placeholder="activity"
            rules={[{ required: true, message: '不得为空' }]}
          />

          <ProFormText
            labelCol={{ span: 8 }}
            width="lg"
            name="activityType"
            label="券子分类"
            placeholder="activityType"
          />

          <ProFormDateTimeRangePicker
            labelCol={{ span: 8 }}
            width={350}
            label="活动时间范围"
            name="activityDateRange"
            fieldProps={{
              placeholder: ['开始时间', '结束时间'],
              format: 'YYYY-MM-DD HH:mm:ss',
            }}
            transform={(e) => {
              return {
                activityStartTime: e[0] || '',
                activityEndTime: e[1] || '',
              };
            }}
            rules={[{ required: true, message: '请选择日期范围' }]}
          />
          <div style={{ width: 400 }} />
          {/* <ProFormDependency name={['activityStartTime']}>
            {({ activityStartTime }) => {
              return (
                <>
                  <ProFormItem label="活动开始时间" labelCol={{ span: 8 }}>
                    <DatePicker
                      style={{ width: '100%' }}
                      value={
                        activityStartTime ? moment(activityStartTime, 'YYYY-MM-DD HH:mm:ss') : null
                      }
                      onChange={onChangeStartTime}
                      showTime
                      format={'YYYY-MM-DD HH:mm:ss'}
                    />
                  </ProFormItem>
                </>
              );
            }}
          </ProFormDependency>

          <ProFormDependency name={['activityEndTime']}>
            {({ activityEndTime }) => {
              return (
                <>
                  <ProFormItem label="活动结束时间" labelCol={{ span: 8 }}>
                    <DatePicker
                      style={{ width: '100%' }}
                      value={
                        activityEndTime ? moment(activityEndTime, 'YYYY-MM-DD HH:mm:ss') : null
                      }
                      onChange={onChangeEndTime}
                      showTime
                      format={'YYYY-MM-DD HH:mm:ss'}
                    />
                  </ProFormItem>
                </>
              );
            }}
          </ProFormDependency> */}

          <ProFormSelect
            labelCol={{ span: 8 }}
            width="lg"
            name="businessModel"
            label="业务模式"
            options={ENUM_BUSINESS_MODEL}
            placeholder=""
          />

          <ProFormSelect
            labelCol={{ span: 8 }}
            width="lg"
            name="couponTypeName"
            label="券类型"
            options={ENUM_COUPON_TYPE_NAME}
            placeholder=""
          />
          <ProForm.Group>
            <ProFormSelect
              labelCol={{ span: 8 }}
              width="lg"
              name="issuerName"
              label="发放商户名称"
              options={ENUM_ISSUER_NAME}
              placeholder=""
            />
            <ProFormSelect
              labelCol={{ span: 8 }}
              width="lg"
              name="couponSource"
              label="发码机构"
              options={ENUM_COUPON_SOURCE}
              placeholder=""
            />
          </ProForm.Group>

          <ProFormSelect
            labelCol={{ span: 8 }}
            width="lg"
            name="placeStyle"
            label="发放性质"
            options={ENUM_PLAC_STYLE}
            placeholder=""
          />

          {/* 舍弃旧版 */}
          {/* <ProFormSelect
            labelCol={{ span: 8 }}
            width="lg"
            name="useChannelName"
            label="券使用渠道描述"
            options={OptionsUseChannelList}
            placeholder=""
          /> */}
          {/* 添加新版---tenantList---tenantFather */}
          <ProFormDependency name={['tenantFather']}>
            {({ tenantFather }) => {
              return (
                <TenantRadio
                  tenantFather={tenantFather}
                  formRef={formRef}
                  OptionsTenantList={OptionsTenantList}
                />
              );
            }}
          </ProFormDependency>

          <ProFormText
            labelCol={{ span: 8 }}
            width="lg"
            name="profileCouponSource"
            label="券来源"
            placeholder="profileCouponSource"
          />

          <ProFormRadio.Group
            labelCol={{ span: 8 }}
            width="lg"
            name="needCheck"
            label="是否需要验码"
            options={[
              {
                label: '否',
                value: 0,
              },
              {
                label: '是',
                value: 1,
              },
            ]}
          />

          <ProFormSelect
            labelCol={{ span: 8 }}
            width="lg"
            name="businessType"
            label="业务类型"
            placeholder="请选择"
            options={OptionsBusinessTypeList}
          />

          <ProFormSelect
            labelCol={{ span: 8 }}
            width="lg"
            name="usecate"
            label="券码用途"
            placeholder="请选择"
            options={OptionsCouponUseCategoryList}
          />

          <ProFormSelect
            labelCol={{ span: 8 }}
            width="lg"
            name="discountLevel"
            label="折扣力度"
            placeholder="请选择"
            options={ENUM_DISCOUNT_LEVEL}
            // rules={[{ required: true, message: '不得为空' }]}
          />

          <ProFormSelect
            labelCol={{ span: 8 }}
            width="lg"
            name="placetypeLevel"
            label="发放形式"
            placeholder="请选择"
            options={ENUM_PLACE_TYPE_LEVEL}
            // rules={[{ required: true, message: '不得为空' }]}
          />

          <ProFormSelect
            labelCol={{ span: 8 }}
            width="lg"
            name="sortGroup"
            label="排序分组"
            placeholder="请选择"
            options={ENUM_SORT_GROUP}
            rules={[{ required: true, message: '不得为空' }]}
          />

          <ProFormSelect
            labelCol={{ span: 8 }}
            width="lg"
            name="lastestTop"
            label="当天获取置顶"
            placeholder="请选择"
            options={LASTESTTOP}
            rules={[{ required: true, message: '不得为空' }]}
          />

          <ProFormSelect
            labelCol={{ span: 8 }}
            width="lg"
            name="regionLimitType"
            label="区域限制类型"
            placeholder="请选择"
            options={ENUM_REGION_LIMIT_TYPE}
            rules={[{ required: true, message: '不得为空' }]}
          />

          <ProFormSelect
            mode="multiple"
            labelCol={{ span: 8 }}
            width="lg"
            name="regionNames"
            label="区域"
            placeholder="请选择"
            options={OptionsRegionList}
            // rules={[{ required: true, message: '不得为空' }]}
            fieldProps={{
              maxTagCount: 'responsive',
              dropdownMatchSelectWidth: 350,
              dropdownStyle: {
                width: 350,
              },
              width: '350',
            }}
          />
        </ProForm.Group>
        <ProForm.Group>
          <ProFormSelect
            labelCol={{ span: 8 }}
            // width="lg"
            style={{ width: '48%' }}
            name="couponTagsLabel"
            label="券标签"
            placeholder="请选择"
            // @ts-ignore
            options={uniqBy(OptionsCouponTagList, 'value')}
            fieldProps={{
              onChange: optionsCouponTagListChange,
            }}
          />
          <ProFormSelect
            labelCol={{ span: 8 }}
            // width={230}
            style={{ width: 128, marginLeft: '-48%' }}
            name="couponTagsValue"
            label={null}
            placeholder="请选择"
            options={OptionsCouponTagsValueList}
          />
          <ProFormDependency name={['couponTagsLabel', 'couponTagsValue']}>
            {({ couponTagsLabel, couponTagsValue }) => {
              return (
                <div style={{ marginLeft: -430 }}>
                  <Button
                    onClick={() => {
                      handlecouponTags(couponTagsLabel, couponTagsValue);
                    }}
                    type="primary"
                  >
                    新增
                  </Button>

                  <Button
                    style={{ marginLeft: 16 }}
                    onClick={() => {
                      formRef.current?.setFieldValue('couponTags', '');
                      dispatch('setFormValue', { couponTags: '' });
                    }}
                    type="primary"
                  >
                    清空
                  </Button>
                </div>
              );
            }}
          </ProFormDependency>
        </ProForm.Group>
        <ProForm.Group>
          <div style={{ paddingLeft: 132 }}>
            <ProFormTextArea
              labelCol={{ span: 8 }}
              width={700}
              label={null}
              name="couponTags"
              placeholder="couponTags"
              fieldProps={{
                autoSize: {
                  minRows: 4,
                  maxRows: 16,
                },
              }}
              style={{ width: 1000 }}
              // rules={[{ required: true, message: '不得为空' }]}
            />
          </div>
        </ProForm.Group>

        <ProForm.Group>
          <ProFormSelect
            mode="multiple"
            labelCol={{ span: 8 }}
            width="lg"
            name="filterTags"
            label="券过滤标签"
            placeholder="请选择"
            options={OptionsFilterTagList}
            rules={[]}
            fieldProps={{
              maxTagCount: 'responsive',
            }}
          />
        </ProForm.Group>
        <ProForm.Group>
          <ProFormText
            labelCol={{ span: 8 }}
            width="lg"
            name="extandDiscountPrice"
            label="折扣描述"
            placeholder="extandDiscountPrice"
          />

          <ProFormText
            labelCol={{ span: 8 }}
            width="lg"
            name="extandLimitationDescB"
            label="折扣门槛描述"
            placeholder="extandLimitationDescB"
          />
        </ProForm.Group>

        <ProForm.Group>
          <ProFormSelect
            labelCol={{ span: 8 }}
            style={{ width: '48%' }}
            name="extandValueOne"
            label="扩展属性"
            placeholder="请选择"
            options={OptionsExtandvalueInfoList}
            fieldProps={{
              onChange: extandValueOneChange,
            }}
          />
          <ProFormDependency name={['extandValueOne']}>
            {({ extandValueOne }) => {
              const typeList =
                OptionsExtandvalueInfoList.filter((item: any) => item.value === extandValueOne) ||
                [];
              if (typeList.length > 0 && typeList[0].type === 1) {
                return (
                  <div style={{ marginLeft: '-40%' }}>
                    <ProFormRadio.Group
                      width={128}
                      name="extandValueTwo"
                      options={[
                        {
                          label: 'YES',
                          value: 'YES',
                        },
                        {
                          label: 'NO',
                          value: 'NO',
                        },
                      ]}
                    />
                  </div>
                );
              }
              return (
                <div style={{ marginLeft: '-40%' }}>
                  <ProFormText
                    labelCol={{ span: 0 }}
                    width={128}
                    name="extandValueTwo"
                    label={null}
                    placeholder={'请输入'}
                  />
                </div>
              );
            }}
          </ProFormDependency>

          <div style={{ marginLeft: -430 }}>
            <ProFormDependency name={['extandValueOne', 'extandValueTwo']}>
              {({ extandValueOne, extandValueTwo }) => {
                return (
                  <Button
                    onClick={() => {
                      handleExtandValue(extandValueOne, extandValueTwo);
                    }}
                    type="primary"
                  >
                    新增
                  </Button>
                );
              }}
            </ProFormDependency>
            <Button
              style={{ marginLeft: 16 }}
              onClick={() => {
                formRef.current?.setFieldValue('extandValue', '');
                dispatch('setFormValue', { extandValue: '' });
              }}
              type="primary"
            >
              清空
            </Button>
          </div>
        </ProForm.Group>
        <ProForm.Group>
          <div style={{ paddingLeft: 132 }}>
            <ProFormTextArea
              width={700}
              label={null}
              name="extandValue"
              placeholder="extandValue"
              fieldProps={{
                autoSize: {
                  minRows: 4,
                  maxRows: 16,
                },
              }}
              // rules={[{ required: true, message: '不得为空' }]}
            />
          </div>
        </ProForm.Group>
        <ProForm.Group>
          <ProFormTextArea
            labelCol={{ span: 8 }}
            width={700}
            label="券功能"
            name="activityFunction"
            placeholder="activityFunction"
            fieldProps={{
              autoSize: {
                minRows: 4,
                maxRows: 6,
              },
            }}
          />
          <div style={{ width: 500 }} />
          <ProFormTextArea
            labelCol={{ span: 8 }}
            width={700}
            label="券产品描述"
            name="useProductName"
            placeholder="useProductName"
            fieldProps={{
              autoSize: {
                minRows: 4,
                maxRows: 6,
              },
            }}
          />
          <div style={{ width: 500 }} />
          <ProFormTextArea
            labelCol={{ span: 8 }}
            width={700}
            label="使用规则描述"
            name="useDesc"
            placeholder="useDesc"
            fieldProps={{
              autoSize: {
                minRows: 4,
                maxRows: 6,
              },
            }}
          />
          <div style={{ width: 500 }} />
          <ProFormTextArea
            labelCol={{ span: 8 }}
            width={700}
            label="Campaign Code"
            name="campaigncode"
            placeholder="Campaign Code"
            fieldProps={{
              autoSize: {
                minRows: 4,
                maxRows: 6,
              },
            }}
          />
        </ProForm.Group>
      </div>
    </Config.Group>
  );
};

export default BasicInfo;
